/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package szachy;
import java.io.Serializable;
import java.lang.Math;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author Robert
 */
public class Skoczek extends Figura implements Serializable{
    private static final long serialVersionUID = 1L;
    public Skoczek(char kolor, String nazwa, String rodzaj){
        this.kolor=kolor;
        iloscRuchu=3; // to chyba tu niepotrzebne
        this.nazwa=nazwa;
        this.rodzaj=rodzaj;
    }
     public boolean mozliwyRuch(int fromX, int fromY, int toX, int toY,IGra g){
     boolean answer = true;
     
     if(Math.abs(fromX-toX)==1 && Math.abs(fromY-toY)==2){
            try {
                if (g.CzyZajete(toX, toY)) {
                    answer = false;
                }
            } catch (RemoteException ex) {
                Logger.getLogger(Skoczek.class.getName()).log(Level.SEVERE, null, ex);
            }
     }else if (Math.abs(fromX-toX)==2 && Math.abs(fromY-toY)==1){
            try {
                if (g.CzyZajete(toX, toY)) {
                    answer = false;
                }
            } catch (RemoteException ex) {
                Logger.getLogger(Skoczek.class.getName()).log(Level.SEVERE, null, ex);
            }
     }else
         answer=false;
     return answer;
     }

     public boolean mozliwoscBicia(int fromX, int fromY, int toX, int toY,IGra g){
         try {
            if (g.ZwrocFigure(toX, toY).CoTo().equals("krol")) {
                return false;
            }
        } catch (RemoteException ex) {
            Logger.getLogger(Pion.class.getName()).log(Level.SEVERE, null, ex);
        }
            if(Math.abs(fromX-toX)==1 && Math.abs(fromY-toY)==2) return true;
            else if (Math.abs(fromX-toX)==2 && Math.abs(fromY-toY)==1) return true;
            else return false;
     }
}
